<?php

require_once '../ptnhuan-web1/libraries/utilites/functions.php';
$path =  "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);//realpath tráº£ vá» Ä‘Æ°á»ng dáº«n
$fimls = mreadFile($full_path);//Ä‘á»c file
?>
<form method="POST" >
    <input type="text" name="rating" placeholder="rating 1">
    <input type="text" name="rating1" placeholder="rating 2">
    <input type="submit" name="submit" value="Search">
</form>
<?php
$loi = false;
for ($i = 0; $i < count($fimls); $i++):
    $b = trim($fimls[$i], "\t\n\r ");//trim loáº¡i bá» khoáº£ng tráº¯ng vÃ  kÃ½ tá»± Ä‘Æ°á»£c xÃ¡c Ä‘á»‹nh trÆ°á»›c khÃ¡c tá»« cáº£ hai phÃ­a cá»§a má»™t chuá»—i
    $mang = explode(";", $b); // explode phÃ¡ vá»¡ chuá»—i ra va cho vao $mang;
    if ($b != "") {//bá» nhá»¯ng dÃ²ng trá»‘ng vÃ  khÃ´ng cÃ³ giÃ¡ trá»‹
        if (isset($_POST["rating"])) {
            if (is_numeric($_POST["rating"]) && is_numeric($_POST["rating1"])) {// Kiem tra ngÆ°á»i nháº­p cÃ³ pháº£i lÃ  so khÃ´ng vÃ  tráº£ vá» g/t True náº¿u Ä‘Ãºng vÃ (ngÆ°á»£c láº¡i)
                if ($mang[3] >= (double) $_POST["rating"] && $mang[3] <= (double) $_POST["rating1"]) {// Láº¥y rating trong khoáº£n ngÆ°á»i dÃ¹ng nháº­p.
                    ?>
                    <div class="item">
                        <img src='../ptnhuan-web1/public/images/films/<?php if (!empty($mang[1])) echo $mang[1]; ?>' algin="left"/>
                    <?php if (!empty($mang[2])) echo $mang[2]; ?>
                    <?php if (!empty($mang[3])) echo $mang[3]; ?><pre><a href="edit_File.php?if=<?php echo $mang[0]; ?>">edit</a></pre>
                    </div>
                    <?php 
                }
            }
            else
                $loi = 2;
        }
        else {
            ?> 
<img src='../ptnhuan-web1/public/images/films/<?php if (!empty($mang[1])) echo $mang[1]; ?>'/>
            <?php if (!empty($mang[2])) echo $mang[2]; ?>
            <?php if (!empty($mang[3])) echo $mang[3]; ?><pre><a href="edit_File.php?if=<?php echo $mang[0]; ?>"> edit</a></pre>
            <BR>
            <?php
        }
    }
endfor;
if ($loi == true)
    echo "Please try again !";